package com.pets.controller;

import com.pets.entity.Knowledge;
import com.pets.qo.KnowledgeAddQO;
import com.pets.qo.UserRegisterQO;
import com.pets.service.KnowledgeService;
import com.pets.util.PageData;
import com.pets.util.Result;
import com.pets.vo.KnowledgesByPageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping(value="/knowledge")
public class KnowledgeController {
    @Autowired
    private KnowledgeService knowledgeService;

    /**
     * 分页显示
     * @param page
     * @param pageSize
     * @return
     */
    @RequestMapping(value="/selectKnowledgesByPage")
    public ModelAndView selectKnowledgesByPage(int page,int pageSize){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/user/news");
        PageData<KnowledgesByPageVO> knowledges = knowledgeService.selectKnowledgesByPage(page,pageSize);
        modelAndView.addObject("pd",knowledges);
        return modelAndView;
    }

    @ResponseBody
    @RequestMapping(value = "/knowledgeAdd", method = RequestMethod.POST)
    public Result knowledgeAdd(KnowledgeAddQO knowledgeAddQO) {
        Result result = knowledgeService.KnowledgeAddQO(knowledgeAddQO);
        return result;
    }


}
